﻿using RpcSync.Service.Interface;
using WeDonekRpc.Client.Attr;
using WeDonekRpc.Client.Interface;
using WeDonekRpc.Client.Ioc;

namespace RpcSync.Service.Accredit
{
    [IocName("db")]
    [ClassLifetimeAttr(ClassLifetimeType.SingleInstance)]
    internal class DbAccredit : IAccreditCollect
    {
        private readonly IIocService _Unity;
        public DbAccredit (IIocService unity)
        {
            this._Unity = unity;
        }
        public bool Get (string accreditId, out IAccreditToken token)
        {
            using (IocScope score = this._Unity.CreateScore())
            {
                token = this._Unity.Resolve<IAccreditToken>("db");
                return token.Init(accreditId);
            }
        }
        public void Accredit (AccreditToken token)
        {
            using (IocScope score = this._Unity.CreateScore())
            {
                IAccreditToken accredit = this._Unity.Resolve<IAccreditToken>("db");
                accredit.Create(token);
            }
        }
    }
}
